/**
 * this class encapsulates the setter and scale method
 * for every rectangle, bot not squares.
 */
public class Rectangle implements IRectangle {

	private double a, b;
	
	/**
	 * a rectangle consists of two length-values.
	 * these lengths must be positiv.
	 * the 2 length-values may be the same.
	 */
	protected Rectangle(double a, double b) {
		setA(a);
		setB(b);
	}

	/**
	 * the lenght a must be positiv.
	 */
	public void setA(double a) {
		validateLength(a);
		this.a = a;
	}
	
	public double getA() {
		return a;
	}
	
	public double getB() {
		return b;
	}
	
	/**
	 * the lenght b must be positiv.
	 */
	public void setB(double b) {
		validateLength(b);
		this.b = b;
	}
	
	/**
	 * length must be > 0
	 */
	private void validateLength(double l) {
		if(l <= 0) {
			throw new IllegalArgumentException();
		}
	}

	/**
	 * the scalar must be positiv and not zero ( > 0)
	 * the scalar changes the size of all length-values
	 */
	@Override
	public void scale(double factor) {
		if(factor <= 0) { //scalar has to be > 0
			throw new IllegalArgumentException();
		}
		setA(getA() * factor);
		setB(getB() * factor);
	}

	/**
	 * calculates the area of the rectangle
	 * using the variables a and b.
	 */
	@Override
	public final double area() {
		return getA()*getB();
	}

	/**
	 * calculates the perimeter of the rectangle
	 * using the variables a and b.
	 */
	@Override
	public final double perimeter() {
		return (2*(getA()+getB()));
	}
	
	/**
	 * this returns always 4.
	 *
	 */
	@Override
	public int edges() {
		return 4;
	}
}
